package org.example;

import java.util.Comparator;
import java.util.TreeMap;

public class TreeMap_Demo1 {
    public static void main(String[] args) {
        TreeMap<Integer,String> tm = new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //降序     升序排序是o1-o2
                return o1-o2;
            }
        });
        tm.put(1,"a");
        tm.put(2,"b");
        tm.put(3,"c");
        tm.put(4,"d");
        tm.put(5,"e");
        System.out.println(tm);
        System.out.println("------------------");
        TreeMap<Student,String> tm1 = new TreeMap<>();
        tm1.put(new Student("zhangsan",13), "南京");
        tm1.put(new Student("lisi",14), "北京");
        tm1.put(new Student("wangwu",15), "上海");
        tm1.put(new Student("zhaoliu",16), "广州");
        tm1.put(new Student("sunqi",17), "深圳");
        System.out.println(tm1);
    }
}
